<div class="container-xl">
  [[ .StocksModuleNav ]]
  <div class="row">
    <div class="col-8">
      <div class="card">
        <ul class="nav nav-tabs nav-tabs-alt" data-toggle="tabs">
          <li class="nav-item">
            <a href="#tabs1" class="nav-link active" data-toggle="tab">
              <!-- SVG icon code -->
              首页
            </a>
          </li>
          <li class="nav-item">
            <a href="#tabs2" class="nav-link" data-toggle="tab">
              <!-- SVG icon code -->
              基本面
            </a>
          </li>
          <li class="nav-item">
            <a href="#tabs3" class="nav-link" data-toggle="tab">
              <!-- SVG icon code -->
              买卖记录
            </a>
          </li>
        </ul>
        <div class="card-body">
          <div class="tab-content">
            <div class="tab-pane active show" id="tabs1">
              <h5>{{ .StockModel.COMPANY_ABBR }} {{ .StockModel.COMPANY_CODE }}</h5>
              {{ if eq .StockModel.COMPANY_CODE "index" }}
              <div class="row">
                <div class="col">
                  <a href="https://xueqiu.com/S/SH000001">雪球网-上证指数</a>
                </div>
                <div class="col">
                  <a href="https://xueqiu.com/S/SZ399001">雪球网-深证成指</a>
                </div>
                <div class="col">
                  <a href="https://xueqiu.com/S/SZ399006">雪球网-创业板数</a>
                </div>
                <div class="col">
                  <a href="https://xueqiu.com/S/SH000688">雪球网-科创50</a>
                </div>
              </div>
              {{ else }}
              <div class="row">
                <div class="col">
                  <a href="https://xueqiu.com/S/{{ .StockModel.COMPANY_KIND }}{{ .StockModel.COMPANY_CODE }}">雪球网</a>
                </div>
              </div>
              {{ end }}
            </div>
            <div class="tab-pane active show" id="tabs2">
              123
            </div>
            <div class="tab-pane active show" id="tabs3">
              456
            </div>
          </div>
        </div>
      </div>
      {{ range $index, $map := .CommentsRows }}

      <div id="comm_id_{{$map.comm_id}}" class="card d-flex flex-column my-2">
        <div class="card-body d-flex flex-column">
          <!-- <h3 class="card-title"><a href="#">How do you know she is a witch?</a></h3> -->
          <div class="text-muted border-bottom">{{ $map.comm_content }}</div>
          <div class="d-flex align-items-center pt-2 mt-auto">
            <img src="/static/img/defautl_head.jpg" style="width: 44px; height: 44px; border-radius: 50%;" />
            <div class="ms-3">
              <small>{{ $map.created_by }} <span class="text-muted">{{ $map.created_at }}</span></small>
              <small class="d-block text-muted">
                操作：
                <a class="text-dark" href="javascirpt:void(0);" onclick="deleteComment('{{ $map.comm_id }}')">删贴</a>
              </small>
            </div>

          </div>
        </div>
      </div>

      {{ end }}


      {{ if .HasComments }}
      <div class="d-flex align-items-center my-2">
        {{.PageControl}}
      </div>
      {{ else }}
      <div class="alert alert-info my-2" role="alert">
        该股票暂时没有人发表过评论，您可以作第一次发言哦～
      </div>
      {{ end }}

    </div>
    <div class="col-4">
      <div class="card">
        <div class="card-body">
          <figure>
            <blockquote class="blockquote fw-lighter fs-6">
              <p>股市不是天天能赚钱的地方</p>
            </blockquote>
            <figcaption class="blockquote-footer fw-lighter text-end">
              华尔街没有新鲜事 <cite title="Source Title">摘自网络</cite>
            </figcaption>
          </figure>
          <div class="my-3">
            <label class="form-label"></label>
            <textarea class="form-control" rows="6" id="comments" placeholder="针对这个股票，记录一下现在的想法吧"></textarea>
          </div>
          <button onclick="postComments();" class="btn btn-light w-100">发表</button>
        </div>
      </div>
    </div>
  </div>
</div>

<script>
  function deleteComment(id) {
    $.post("/stocks/weigh/deletecomments", { id: id }, function (json) {
      if (json.flag) {
        alert('删除成功');
        $("#comm_id_" + id).remove();
      } else {
        alert(json.msg);
      }
    });
  }
  function postComments() {
    var content = document.getElementById("comments").value;
    var code = 'index';
    if (content.length == 0) {
      document.getElementById("comments").select();
      return;
    }
    $.post("/stocks/weigh/savecomments", { content: content, code: code }, function (json) {
      if (json.flag) {
        alert('提交成功');
        window.location.reload();
      } else {
        alert(json.msg);
      }
    });
  }
  document.addEventListener('DOMContentLoaded', function () {

  });
</script>